<template>
  <div class="top">
    <h1 class="site_title">项目管理系统</h1>
    <div class="userinfo">
      <div class="icon">
        <el-badge :value="totalMsg" class="item">
          <!-- <i class="el-icon-message" @click="$router.push('/msg_work')"></i> -->
          <el-button size="small" icon="el-icon-message-solid" type="primary"
          @click="$router.push('/msg')"></el-button>
        </el-badge>
      </div>
      <div>
        <el-dropdown @command="handleCommand">
          <span class="el-dropdown-link">
            <div class="user">
              <div class="user_block">
                  <i class="el-icon-user-solid" style="font-size: 26px;"></i>
              </div>
              <span class="username">{{userInfo && userInfo.userName}}</span>
            </div>
            
          </span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item>
              <i class="el-icon-user"></i>
              {{userInfo && userInfo.userName}}
            </el-dropdown-item>
            <el-dropdown-item>
              <i class="el-icon-phone-outline"></i>
              {{userInfo && userInfo.mobile}}
            </el-dropdown-item>
            <el-dropdown-item command="logout">
              <i class="el-icon-back"></i>退出
            </el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {};
  },
  created() {
    if (!this.userInfo) {
      this.$router.push("/login");
    }
    this.$store.dispatch("getTotalMsg");
  },
  methods: {
      handleCommand(command) {
      if (command === "logout") {
        localStorage.removeItem("token");
        localStorage.removeItem("loginInfo");
        this.$router.push("/login");
      }
    }
  },
  computed: {
    totalMsg() {
      return this.$store.state.totalMsg;
    },
    userInfo() {
      return this.$store.state.login.userInfo;
    }
  }
};
</script>

<style lang="less" scoped>
@import "./index.less";
</style>